package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.reggie.common.R;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.dto.SetmealDto;
import com.itheima.reggie.service.SetmealDishService;
import com.itheima.reggie.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 刘付磊
 * @date 2021/10/20 0020
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @Autowired
    private SetmealDishService setmealDishService;

    @PostMapping
    public R<String> save(@RequestBody SetmealDto setmealDto){
        setmealService.saveWithDish(setmealDto);
        return R.success("添加套餐成功");
    }
    @GetMapping("/page")
    public R<IPage<Setmeal>> page(String name,int page,int pageSize){
        R<IPage<Setmeal>> page1 = setmealService.page(name, page, pageSize);
        return page1;
    }

    @DeleteMapping
    public R<String> removeWithDish(@RequestParam List<Long> ids){
        setmealService.removeWithDish(ids);
        return R.success("删除套餐成功");
    }
    @GetMapping("/list")
    public R<List<Setmeal>> list(Setmeal setmeal){
        log.info("setmeal={}",setmeal);
        R<List<Setmeal>> list = setmealService.listWith(setmeal);
        return list;
    }
    @PostMapping("/status/0")
    public R<String> tatu(String ids){
        log.info("ids={}",ids);
        setmealService.tatu(ids);
        return R.success("套餐状态修改成功");
    }
    @GetMapping("/{id}")
    public R<SetmealDto> get(@PathVariable Long id){
        log.info("id={}",id);
        R<SetmealDto> r = setmealService.get(id);
        return r;
    }
    @PutMapping
    public R<String> upDate(@RequestBody SetmealDto setmealDto){
        log.info("setmealDto={}",setmealDto);
        setmealService.upDate(setmealDto);
        return R.success("修改成功");
    }
}
